//
//  HideTextVeiw.m
//  Koina
//
//  Created by welldone on 13-9-6.
//  Copyright (c) 2013年 net.koina. All rights reserved.
//

#import "HideTextVeiw.h"
#import "StringTool.h"
#import "config.h"


@interface HideTextVeiw ()<UITextViewDelegate,UIScrollViewDelegate>


-(void)btnClik:(UIButton*)sender;

@end



@implementation HideTextVeiw
@synthesize hideLab;


-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder]) {
        
        self.delegate = self;
       
        
        hideLab = [[UILabel alloc]initWithFrame:CGRectMake(8, 12, 0, 0)];
        [hideLab setFont:[UIFont systemFontOfSize:13]];
        [hideLab setLineBreakMode:NSLineBreakByCharWrapping];
        [hideLab setNumberOfLines:0];
        [hideLab setTextColor:[UIColor colorWithRed:(float)0xaa/(float)0xff green:(float)0xaa/(float)0xff blue:(float)0xaa/(float)0xff alpha:1]];
        [self addSubview:hideLab];

    }
    return self;
}




-(void)btnClik:(UIButton*)sender{
    if (sender.tag==12) {
        [self resignFirstResponder];
    }

}



-(void)setTxColor:(UIColor *)textColor{
    [self setTextColor:textColor];
}


-(void)setHideText:(NSString*)text{
    
    [hideLab setFont:self.font];
    
    CGSize labSize = [text sizeWithFont:hideLab.font constrainedToSize:CGSizeMake(self.frame.size.width-hideLab.frame.origin.x*2, self.frame.size.height-hideLab.frame.origin.y*2) lineBreakMode:NSLineBreakByCharWrapping];
    
    
    CGRect buf = hideLab.frame;
    buf.size.width = labSize.width;
    buf.size.height = labSize.height;
    [hideLab setFrame:buf];
    
    
    [hideLab setText:text];
}

-(NSString*)getHideText{
    return hideLab.text;
}


-(Boolean)textIsChanged{
    return  ![self.text isEqualToString:hideLab.text];
}


-(void)hideSmail:(Boolean)hide{
    if (hide) {
        self.inputAccessoryView = nil;
    }
}





-(void)textDicChange:(NSString*)str{
    
    if (![str isEqualToString:@""]) {
        [hideLab setHidden:YES];
    }else{
        [hideLab setHidden:false];
    }
    
}



-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


@end
